<?php
/**
 * 提现操作
 *
 *
 *
 * @copyright  Copyright (c) 2014-2015 TuntronKJ Inc. (http://www.tuntron.com)
 * @license    http://www.tuntron.com
 * @link       http://www.tuntron.com
 * @since      File available since Release v1.1
 */
defined('InTuntronKJ') or exit('Access Invalid!');
class withdrawControl extends BaseLotteryHallControl{
	public function indexOp(){
		
		$uid = $_SESSION['uid'];
		$model_bank = Model('bank');
		$model_member = Model('member');
		$model_param = Model('params');
		
		$today_zero = strtotime('today');
		$fromTime = $today_zero;
		$toTime = $today_zero+3600*24;
		
		$paramlist = $model_param->getParamsList();						//系统配置信息
		$paymentInfo = $model_bank->getPaymentInfo(array('uid'=>$uid));
		$memberinfo = $model_member->getMemberInfo(array('uid'=>$uid));

		$withdraw = array();
		if(!empty($paymentInfo) && is_array($paymentInfo)){
			$bankinfo = $model_bank->getBankInfo(array('id'=>$paymentInfo['bankId']));
			$withdraw['WithDrawTitle'] = $bankinfo['name'];
			$withdraw['AccoutNo'] = $paymentInfo['account'];
			$withdraw['AccoutName'] = $paymentInfo['username'];
		}
		
		$withdraw['AvailablePoint'] = number_format($memberinfo['coin'],2);
		$withdraw['MaxWithdrawCount'] = 3;
		$withdraw['MinWithdrawAmount'] = 100;
		$withdraw['MaxWithdrawAmount'] = 100000;
		$withdraw['RemainWithdrawCount'] = 3;
		
		Tpl::output('withdraw',$withdraw);
		Tpl::output('paymentInfo',$paymentInfo);
		Tpl::showpage('withdraw');
	}
	
	public function WithdrawalSubmitOp(){
		//提现后资金冻结、每日提现次数、提现金额
		$model_member = Model('member');
		$model_bank = Model('bank');
		$model_cash = Model('cash');
		$uid = $_SESSION['uid'];
		print_r($_POST);exit;
		$paymentInfo = $model_bank->getPaymentInfo(array('uid'=>$uid));
		$memberinfo = $model_member->getMemberInfo(array('uid'=>$uid));
		
		$money = $_POST['Money'];						//提现金额
		$fundPassword = $_POST['FundPassword'];			//资金密码
		$num = 1;										//提现次数

		if($memberinfo['coin']< $money){
			$output = json_encode("提现金额不足,提现失败!");			
		}elseif($memberinfo['coinPassword'] != md5($fundPassword)){
			$output = json_encode("资金密码错误,提现失败!");
		}elseif($money < 100 || $money > 100000){
			$output = json_encode("单次提现金额最低100元，最高100000元!");
		}elseif($num > 3){
			$output = json_encode("今日提现次数已超过3次，提现失败!");
		}else{
			
			$param = array(
				'uid'			=>$memberinfo['uid'],
				'actionTime'	=>time(),
				'amount'		=>$money,
				'bankId'		=>$paymentInfo['bankId'],
				'account'		=>$paymentInfo['account'],
				'username'		=>$paymentInfo['username'],
				'state'			=>1,
				'isDelete'		=>0,
				'info'			=>'',
				'flag'			=>0,
		
			);
			$insert = $model_cash->addUserCash($param);
			
			if($insert){
				// 添加用户资金流动日志
				$model_bat->addCoin(array(
						'uid'=>$memberinfo['uid'],
						'type'=>$param['type'],
						//'playedId'=>$para['playedId'],
						'liqType'=>$liqType,
						'info'=>$info,
						'extfield0'=>$r,
						'extfield1'=>$param['serializeId'],
						//'extfield2'=>$data['orderId'],
						'coin'=>-$money,
						//'fcoin'=>$amount
				));
				$output = json_encode("申请成功,请等待管理员审批!");
			}else{
				$output = json_encode("申请失败,请重新提交!");
			}
		}
		echo $output;
		exit();

	}



}
